// Fill the DB with example data on startup

import { Meteor } from 'meteor/meteor';
import { Posts } from '../../api/posts/posts.js';
import { Shops } from '../../api/shops/shops.js';
import { AdminMessages } from '../../api/admin_messages/admin_messages.js';

Meteor.startup(() => {

  if (Posts.find().count() === 0) {
    const data2 = [
      {
        title: '员工平台已经建立',
        body: '员工平台已经建立员工平台已经建立员工平台已经建立员工平台已经建立员工平台已经建立',
        author: "未名",
        createdAt: new Date(),
      },
      {
        title: '让门店多多受益',
        body: '让门店多多受益让门店多多受益让门店多多受益让门店多多受益让门店多多受益让门店多多受益',
        author: "未名",
        createdAt: new Date(),
      },
      {
        title: '三赢：门店、司机、乘客',
        body: '三赢：门店、司机、乘客三赢：门店、司机、乘客三赢：门店、司机、乘客三赢：门店、司机、乘客',
        author: "未名",
        createdAt: new Date(),
      },
      {
        title: '积极响应新政',
        body: '积极响应新政积极响应新政积极响应新政积极响应新政积极响应新政积极响应新政积极响应新政积极响应新政',
        author: "未名",
        createdAt: new Date(),
      },
    ];

    data2.forEach(post => Posts.insert(post));
  }

  if (Shops.find().count() === 0) {
    const data3 = [
      {
        shopCharge: "陈亮",
        address: "成都沙湾路",
        cover_url: '/img/shops/shop0.jpg',
        shopCharge_id: "id",
        name: "滴滴车主俱乐部成都沙湾店",
        description: "滴滴车主俱乐部成都沙湾店滴滴车主俱乐部成都沙湾店滴滴车主俱乐部成都沙湾店滴滴车主俱乐部成都沙湾店滴滴车主俱乐部成都沙湾店",
        createdAt: new Date(),
        foundedAt: "2016年7月6日",
        tel: "0285-333234233",
        hotLine: "40003332",
        area: "西南地区",
        mail: 'xsqfeather@126.com',
        customqq: '626754503',
        customwexin: 'xsqfeather',
        hrqq: '45634534',
        hremail: 'hr889@163.com',
        province: "四川"

      },
      {
        shopCharge: "风清扬",
        address: "上海长江西路",
        cover_url: '/img/shops/shop1.jpg',
        shopCharge_id: "id",
        name: "滴滴车主俱乐部上海长江西路店",
        description: "滴滴车主俱乐部上海长江西路店滴滴车主俱乐部上海长江西路店滴滴车主俱乐部上海长江西路店滴滴车主俱乐部上海长江西路店滴滴车主俱乐部上海长江西路店",
        createdAt: new Date(),
        foundedAt: "2016年7月6日",
        tel: "0285-333234233",
        hotLine: "40003332",
        area: "华东地区",
        mail: 'xsqfeather@126.com',
        customqq: '626754503',
        customwexin: 'xsqfeather',
        hrqq: '45634534',
        hremail: 'hr889@163.com',
        province: "上海"

      },
      {
        shopCharge: "令狐冲",
        address: "北京望京路",
        cover_url: '/img/shops/shop2.jpg',
        shopCharge_id: "id",
        name: "滴滴车主俱乐部上海长江西路店",
        description: "滴滴车主俱乐部上海长江西路店滴滴车主俱乐部上海长江西路店滴滴车主俱乐部上海长江西路店",
        createdAt: new Date(),
        foundedAt: "2016年7月6日",
        tel: "0285-333234233",
        hotLine: "40003332",
        area: '华北地区',
        mail: 'xsqfeather@126.com',
        customqq: '626754503',
        customwexin: 'xsqfeather',
        hrqq: '45634534',
        hremail: 'hr889@163.com',
        province: '北京'
      },
      {
        shopCharge: "陈近南",
        address: "天津望京路",
        cover_url: '/img/shops/shop3.jpg',
        shopCharge_id: "id",
        name: "滴滴车主俱乐部天津店",
        description: "滴滴车主俱乐部天津店滴滴车主俱乐部天津店路店滴滴车主俱乐部上海长江西路店",
        createdAt: new Date(),
        foundedAt: "2016年7月6日",
        tel: "0285-333234233",
        hotLine: "40003332",
        area: "华北地区",
        mail: 'xsqfeather@126.com',
        customqq: '626754503',
        customwexin: 'xsqfeather',
        hrqq: '45634534',
        hremail: 'hr889@163.com',
        province: '天津'
      },
      {
        shopCharge: "韩愈",
        address: "北京滴滴总部",
        cover_url: '/img/shops/shop3.jpg',
        shopCharge_id: "id",
        name: "总部",
        description: "滴滴车主俱乐部天津店滴滴车主俱乐部天津店路店滴滴车主俱乐部上海长江西路店",
        createdAt: new Date(),
        foundedAt: "2016年7月6日",
        tel: "0285-333234233",
        hotLine: "40003332",
        area: "总部",
        mail: 'xsqfeather@126.com',
        customqq: '626754503',
        customwexin: 'xsqfeather',
        hrqq: '45634534',
        hremail: 'hr889@163.com',
        province: '北京'
      },
    ];
    data3.forEach(shop => Shops.insert(shop));

  }

  if (AdminMessages.find().count() === 0) {
    const data4 = [
      {
        state: "未读",
        title: "员工帐号申请",
        content: "陈凯歌的员工账号申请",
        link: "/admin/users/show/id",
        createdAt: new Date(),
      },
      {
        state: "未读",
        title: "员工帐号申请",
        content: "江一燕的员工账号申请",
        link: "/admin/users/show/havefun",
        createdAt: new Date(),
      },
      {
        state: "已读",
        title: "员工帐号申请",
        content: "江一燕的员工账号申请",
        link: "/admin/users/show/havefun",
        createdAt: new Date(),
      },
      {
        state: "已读",
        title: "员工帐号申请",
        content: "多明戈的员工账号申请",
        link: "/admin/users/show/havefun",
        createdAt: new Date(),
      },
    ];
    data4.forEach(admin_message => AdminMessages.insert(admin_message));
  }
  let admin = null;
  if (Meteor.users.find({username: "didiadmin"}).count() == 0) {
    //创建管理员账户
        let admin_id = Accounts.createUser({
            username: 'didiadmin',
            password: 'tianshanglai2017',
          });

        admin = Meteor.users.findOne({_id: admin_id});


  }else{
    admin = Meteor.users.findOne({username: "didiadmin"});
  }
  let head_shop = Shops.findOne({name: "总部"});
  Meteor.users.update(admin._id, {
    $set: {
      role_name: "总部管理员",
      login_time: new Date(),
      shop_belongs: head_shop._id
    }
  });


});
